package com.xjaq.dify.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
@ApiModel("流式聊天完成响应块")
public class ChunkChatCompletionResponse {
    
    @ApiModelProperty("事件类型")
    private String event;
    
    @ApiModelProperty("任务 ID，用于请求跟踪和下方的停止响应接口")
    private String taskId;
    
    @ApiModelProperty("消息唯一 ID")
    private String messageId;
    
    @ApiModelProperty("会话 ID")
    private String conversationId;
    
    @ApiModelProperty("LLM 返回文本块内容")
    private String answer;
    
    @ApiModelProperty("创建时间戳")
    private Long createdAt;
    
    @ApiModelProperty("文件唯一ID")
    private String id;
    
    @ApiModelProperty("文件类型，目前仅为image")
    private String type;
    
    @ApiModelProperty("文件归属，user或assistant")
    private String belongsTo;
    
    @ApiModelProperty("文件访问地址")
    private String url;
    
    @ApiModelProperty("元数据")
    private Metadata metadata;
    
    @ApiModelProperty("语音合成之后的音频块使用 Base64 编码之后的文本内容")
    private String audio;
    
    @ApiModelProperty("详细内容")
    private DataContent data;
    
    @ApiModelProperty("HTTP 状态码")
    private Integer status;
    
    @ApiModelProperty("错误码")
    private String code;
    
    @ApiModelProperty("错误消息")
    private String message;
    
    @ApiModelProperty("workflow 执行 ID")
    private String workflowRunId;
    
    @Data
    @ApiModel("元数据")
    public static class Metadata {
        @ApiModelProperty("模型用量信息")
        private Usage usage;
        
        @ApiModelProperty("引用和归属分段列表")
        private List<RetrieverResource> retrieverResources;
    }
    
    @Data
    @ApiModel("详细内容")
    public static class DataContent {
        @ApiModelProperty("ID")
        private String id;
        
        @ApiModelProperty("关联 Workflow ID")
        private String workflowId;
        
        @ApiModelProperty("节点 ID")
        private String nodeId;
        
        @ApiModelProperty("节点类型")
        private String nodeType;
        
        @ApiModelProperty("节点名称")
        private String title;
        
        @ApiModelProperty("执行序号，用于展示 Tracing Node 顺序")
        private Integer index;
        
        @ApiModelProperty("前置节点 ID，用于画布展示执行路径")
        private String predecessorNodeId;
        
        @ApiModelProperty("节点中所有使用到的前置节点变量内容")
        private Object inputs;
        
        @ApiModelProperty("节点过程数据")
        private Object processData;
        
        @ApiModelProperty("输出内容")
        private Object outputs;
        
        @ApiModelProperty("执行状态")
        private String status;
        
        @ApiModelProperty("错误原因")
        private String error;
        
        @ApiModelProperty("耗时(s)")
        private Float elapsedTime;
        
        @ApiModelProperty("元数据")
        private Object executionMetadata;
        
        @ApiModelProperty("总使用 tokens")
        private Integer totalTokens;
        
        @ApiModelProperty("总费用")
        private String totalPrice;
        
        @ApiModelProperty("货币")
        private String currency;
        
        @ApiModelProperty("开始时间")
        private Long createdAt;
        
        @ApiModelProperty("结束时间")
        private Long finishedAt;
        
        @ApiModelProperty("总步数")
        private Integer totalSteps;
    }
}